#include "symbol.h"
#include <stdlib.h>
#include "def.h"
#include "log.h"


/**
 * @brief 将symbol type转换为字符串
 *
 * @param type symbol type
 * @return char* symbol type 对应的字符串
 */
char *symbol_type_str(
    uint32_t type)
{
    if (type >= symbol_type_max)
    {
        return "type err!";
    }

    static char *type2str[] =
    {
        "num",                //<! 数字
        "plus",               //<! '+'
        "increase",           //<! '++'
        "minus",              //<! '-'
        "decrease",           //<! '--'
        "multiply",           //<! '*'
        "divide",             //<* '/'
        "assign",             //<* '='
        "surplus",            //<* '%'
        "more",               //<* '>'
        "more_equal",         //<* '>='
        "less",               //<* '<'
        "less_equal",         //<* '<='
        "equal",              //<* '=='
        "not_equal",          //<* '!='
        "not",                //<* '!'
        "id",                 //<* 标识符
        "open_parenthesis",   //<! '('
        "close_parenthesis",  //<! ')'
        "open_bracket",       //<! '['
        "close_bracket",      //<! ']'
        "open_brace",         //<! '{'
        "close_brace",        //<! '}'
        "apostrophe",         //<! '''
        "point",              //<! '.'
        "dot",                //<！'",'
        "semicolon",          //<! ';'
        "bits_and",           //<! '&'
        "and",                //<! '&&'
        "bits_or",            //<! '|'
        "or",                 //<! '||'
        "for",                //<! 关键字"for"
        "do",                 //<! 关键字"do"
        "while",              //<! 关键字"while"
        "break",              //<! 关键字"break"
        "continue",           //<! 关键字"continue"
        "char",               //<! 关键字"char"
        "double",             //<! 关键字"double"
        "enum",               //<! 关键字"enum"
        "float",              //<! 关键字"float"
        "int",                //<! 关键字"int"
        "long",               //<! 关键字"long"
        "short",              //<! 关键字"short"
        "signed",             //<! 关键字"signed"
        "struct",             //<! 关键字"struct"
        "union",              //<! 关键字"union"
        "unsigned",           //<! 关键字"unsigned"
        "void",               //<! 关键字"void"
        "if",                 //<! 关键字"if"
        "else",               //<! 关键字"else"
        "goto",               //<! 关键字"goto"
        "character",          //<! 单个字符
        "string",             //<! 字符串
        "switch",             //<! "switch"
        "case",               //<! "case"
        "default",            //<! "default"
        "return",             //<! "return"
        "auto",               //<! "auto"
        "extern",             //<! "extern"
        "register",           //<! "register"
        "static",             //<! "static"
        "const",              //<! "const"
        "sizeof",             //<! "sizeof"
        "typedef",            //<! "typedef"
        "volatile",           //<! "volatile"
    };
    return type2str[type];
}

/**
 * @brief 申请一个symbol
 *
 * @return symbol_st*
 */
symbol_st *symbol_calloc(
    void)
{
    symbol_st *symbol = calloc(sizeof(symbol_st), 1);
    if (symbol == NULL)
    {
        ERR_FUNC_LINE("calloc symbol err!\n");
        return NULL;
    }

    return symbol;
}

/**
 * @brief 释放symbol_st结构体
 *
 * @param symbol
 */
void symbol_free(
    symbol_st *symbol)
{
    if (symbol == NULL)
    {
        return;
    }

    my_free(symbol);
}
